﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Proxy
{
    public class Logger
    {
        private log4net.ILog logger = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
        
        public Logger()
        {
            // pattern layout
            log4net.Layout.PatternLayout layout = new log4net.Layout.PatternLayout();
            layout.ConversionPattern = "%date{dd-MM-yyyy HH:mm:ss:ffff} [%t] %-5p - %m%n"; // pattern
            layout.ActivateOptions(); // activate

            // file appender
            log4net.Appender.RollingFileAppender rollfile = new log4net.Appender.RollingFileAppender();
            rollfile.Layout = layout; // layout pattern
            rollfile.File = "ProxyServerLogfile.txt"; // the output filename
            rollfile.AppendToFile = false; // overwrite any existing file with the same name
            rollfile.MaxFileSize = (1 * 1024 * 1024); // max file size - 10*1024*1024 = 10MB
            rollfile.MaxSizeRollBackups = 10; // keep 10 files
            rollfile.ImmediateFlush = true; // flush after every append
            rollfile.ActivateOptions(); // activate

            log4net.Config.BasicConfigurator.Configure(rollfile);
        }

        public log4net.ILog getLogger()
        {
            return logger;
        }
                
    }
}
